package com.b1502.store2.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.b1502.store2.Bean.NewsBean;
import com.b1502.store2.R;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 刘嘉男
 * on 2017/2/27
 * 描述:
 */

public class NewsAdapter extends BaseAdapter {
    Context context;
  private List<NewsBean> list=new ArrayList<>();

    public NewsAdapter(Context context, List<NewsBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if (convertView==null){
            convertView=View.inflate(context,R.layout.item_news,null);
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder= (ViewHolder) convertView.getTag();
        }

        viewHolder.item_news_tv.setText(list.get(position).getTitle());
        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.init(new ImageLoaderConfiguration.Builder(context).build());
        imageLoader.displayImage(list.get(position).getImgUrl(), viewHolder.item_news_iv);
        return convertView;
    }


    public class ViewHolder {


        private final ImageView item_news_iv;
        private final TextView item_news_tv;

        public ViewHolder(View itemView) {

            item_news_iv = (ImageView) itemView.findViewById(R.id.item_news_iv);
            item_news_tv = (TextView) itemView.findViewById(R.id.item_news_tv);

        }



    }
}
